package nccu.model;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableId;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * This class represents the basic "submission" object that allows for xml file submission
 * persistence and management.
 *
 * @author <a href="mailto:chris.oberle@gmail.com">Chris Oberle</a>
 */
@Entity
@Table(name = "submission")
public class Submission extends BaseObject implements Serializable {

    private static final long serialVersionUID = 3617859655331969141L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column (name="submission_id")
    private Long id;

    @Column(name = "status", length = 100, nullable = false, unique = false)
    private String status;  // required

    @Column(name = "create_date", length = 100, nullable = false, unique = false)
    private Date createDate;// required

    @Column(name = "first_name", nullable = false, length = 100, unique = false)
    private String certifierFirstName; // required

    @Column(name = "last_name", nullable = false, length = 100, unique = false)
    private String certifierLastName; // required


    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getCertifierFirstName() {
        return certifierFirstName;
    }

    public void setCertifierFirstName(String certifierFirstName) {
        this.certifierFirstName = certifierFirstName;
    }

    public String getCertifierLastName() {
        return certifierLastName;
    }

    public void setCertifierLastName(String certifierLastName) {
        this.certifierLastName = certifierLastName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Submission)) return false;

        Submission that = (Submission) o;

        if (!certifierFirstName.equals(that.certifierFirstName)) return false;
        if (!certifierLastName.equals(that.certifierLastName)) return false;
        if (!createDate.equals(that.createDate)) return false;
        if (!status.equals(that.status)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = status.hashCode();
        result = 31 * result + createDate.hashCode();
        result = 31 * result + certifierFirstName.hashCode();
        result = 31 * result + certifierLastName.hashCode();
        return result;
    }

    /**
     * {@inheritDoc}
     */
    public String toString() {
        ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE)
                .append("submission_id", this.id)
                .append("status", this.status)
                .append("createDate", this.createDate)
                .append("certifierFirstName", this.certifierFirstName)
                .append("certifierLastName", this.certifierLastName);
        return sb.toString();
    }
}
